import {Controller, Get, Post, Body, Query, UseGuards} from '@nestjs/common';
import {UserService} from './user.service'
import { AuthGuard } from '@nestjs/passport'
export const jwtConstants = {
    secret: 'secretKey',
};

@Controller('admin')
export class UserController {
    constructor(private readonly UserService:UserService){

    }
    @Post('login')
    async login(@Body() body){
        let {email,password} = body
        // console.log(email,password)
        let result = await this.UserService.login(email,password)
        console.log(result)
        console.log('执行了...')
    //     if(result.length > 0 ){
    //         return {code:0,msg:'登陆成功',email:result[0].email}
    //     }else{
    //         return {code:1,msg:'登陆失败,账号不存在'}
    //     }
        if(result.statusCode==200){
            return result
        }
    }

    @Get()
    index(){
        return {msg:'欢迎来到首页'}
    }
    @UseGuards(AuthGuard('jwt'))
    @Get('list')
    async list(){
        let list=await this.UserService.list()

        return {code:0,list}
    }



    @Get('path')
    async path(@Query('email') email){
        let name = email == "123@qq.com"?'张三':'小明'
        let data =  await this.UserService.path(name)
        // console.log(data)
        let result = this.UserService.treeData(data,"id","pid",'children')
        return result
    }
}
